/*
 *@author: YangJie
 *@date: 2021-04-09 17:53:14
 *@version:
 *@description:参数设置->系统管理->推送记录
 */
import React, { Component } from 'react';
import { Table, Form, Tabs, Card } from 'antd';
import '@/assets/css/settings';
import Paging from '../../../components_yyr/commponent/Paging';
import BasicForm from '../../../components_yyr/common/basicForm';


const { TabPane } = Tabs;
//测试数据
const dataSourceDemo = [
	{
		key: '1',
		id: 1,
		recordTime: 'processName',
		name: 'processType',
		message: '故障维修单：WX-20210412004，设备：机床1(1LA7113-4AA61)',
		status: 'status'
	}
];

//
class PushRecord extends Component {
	state = {
		loading: false, //加载中...
		dataSource: dataSourceDemo, //数据源
		drawerVisible: false, //新增修改抽屉的显示与隐藏
		chooseData: {}, //用checkbox选择好的数据
		drawerTitle: '', //抽屉的标题
		total: 0, //总数据量
		formValues: {}
	};
	componentDidMount() {
		this.fetch({
			pageNum: 1,
			pageSize: 10
		});
		// this.getInfo();
	}
	//初始化加载数据
	fetch = data => {
		// this.setState({ loading: true })
		// this.post('/airCargo/pageList',{data}).then(res => {
		// 	this.setState({
		// 		loading: false,
		// 		dataSource: res.data.data,
		// 		total:res.data.total,
		// 		formValues:data
		// 	});
		// })
	};

	//表单查询
	filterSubmit = values => {
		values.pageNum = this.state.formValues.pageNum;
		values.pageSize = this.state.formValues.pageSize;
		this.fetch(values);
	};

	//头部关键字查询部分
	formList = () => {
		const formList = [
			{ type: 'INPUT', label: '姓名', field: 'factoryName', col: 6 },
			{ type: 'DATE', label: '记录时间', field: 'recordTime', col: 6 },
			{ type: 'INPUT', label: '快速查询', field: 'message', placeholder: '请输入消息内容', col: 6 }
		];
		return formList;
	};

	// 提交modal
	handleSubmit = data => {
		const id = this.state.chooseData && this.state.chooseData.id;
		if (id) {
			data = Object.assign({}, data, { id: id });
			data.updateId = localStorage.getItem('userId');
		} else {
			data.createId = localStorage.getItem('userId');
		}
		this.post('/airCargo/addAirCargo', { data }).then(res => {
			this.success();
			this.fetch({ ...this.state.formValues });
			this.onClose();
		});
	};

	onClose = () => {
		this.setState({
			drawerVisible: false,
			chooseData: {}
		});
		this.modalRef.props.form.resetFields();
	};

	render() {
		const columns = [
			{ title: '序号', width: 100, dataIndex: 'id' },
			{ title: '记录时间', width: 150, dataIndex: 'recordTime' },
			{ title: '姓名', width: 250, dataIndex: 'name' },
			{ title: '消息', width: 600, dataIndex: 'message' },
			{ title: '状态', dataIndex: 'status' }
		];

		const { chooseData, drawerVisible, drawerTitle, dataSource, loading, total, formValues } = this.state;

		//序号旁的checkbox部分
		const rowSelection = {
			onChange: (selectedRowKeys, selectedRows) => {
				console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
			},
			getCheckboxProps: record => ({
				disabled: record.name === 'Disabled User', // Column configuration not to be checked
				name: record.name
			})
		};

		return (
			<div className="shadow-radius">
				<Card>
					<BasicForm formList={this.formList()} filterSubmit={this.filterSubmit} labelSpan={8} wrapperSpan={12} onRef={ref => (this.child = ref)} />
				</Card>
				<Tabs>
					<TabPane tab="推送记录" key="1">
						<Table columns={columns} rowSelection={rowSelection} rowKey={(record, index) => index} dataSource={dataSource} pagination={false} loading={loading} />
						<Paging total={total} formValues={formValues} fetch={pager => this.fetch(pager)} />
					</TabPane>
				</Tabs>

			</div>
		);
	}
}
export default Form.create()(PushRecord);
